package com.ruoyi.weixin.mp.entity.vo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.weixin.mp.entity.MsgTemplate;
import com.ruoyi.weixin.mp.utils.Json;
import lombok.Data;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;

import java.io.Serializable;
import java.util.Date;

/**
 * 模板消息模板
 * @author Nifury
 * @date 2017-9-27
 */
@Data
public class MsgTemplateVo implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;
    private String appid;
    private String templateId;
    private String name;
    private String title;
    private String content;

    private JSONArray data;
    private String url;
    private JSONObject miniprogram;
    private boolean status;
    private Date updateTime;
    public MsgTemplateVo() {

    }
    public MsgTemplateVo(WxMpTemplate mpTemplate,String appid) {
        this.appid = appid;
        this.templateId=mpTemplate.getTemplateId();
        this.title=mpTemplate.getTitle();
        this.name=mpTemplate.getTemplateId();
        this.content = mpTemplate.getContent();
        this.status=true;
    }

    public MsgTemplateVo(MsgTemplate msgTemplate){
        this.id=msgTemplate.getId();
        this.appid=msgTemplate.getAppid();
        this.templateId=msgTemplate.getTemplateId();
        this.name=msgTemplate.getName();
        this.title=msgTemplate.getTitle();
        this.content=msgTemplate.getContent();
        this.data = JSON.parseArray(msgTemplate.getData());
        this.url=msgTemplate.getUrl();
        this.miniprogram=JSON.parseObject(msgTemplate.getMiniprogram());
        this.status=msgTemplate.isStatus();
        this.updateTime=msgTemplate.getUpdateTime();
    }


    @Override
    public String toString() {
        return Json.toJsonString(this);
    }

}
